<template>
    <div class="questionDetailCardCoutainer">

        <div class="userInfoCard">
            <div class="avaterRegion">
                <el-avatar :size="100" ></el-avatar>
            </div>
            <div class="userInfo">
                <span style="opacity: 90%; 
                        font-size: 100%;
                        color: rgb(255, 251, 0);
                        font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;">
                    {{ QuestionStore.currentQuestion?.username }}
                </span>
                <span style="opacity: 45%; font-size: 70%;">ID:{{ QuestionStore.currentQuestion?.user_id }}</span>
                
            </div>
        </div>

        <div class="mainContentCard">
            <div class="topic">
                <h2>{{ QuestionStore.currentQuestion?.title }}</h2>
            </div>
            <div class="content">
                <article>{{ QuestionStore.currentQuestion?.content }}</article>
            </div>
        </div>
        <div class="comentCard">

        </div>
        <div class="answerCard">
            <template v-for="answer in QuestionStore.questionAnswers" :key="answer.id">
                <div class="Acard">
                    <div class="avater_answer">
                        <el-avatar :size="50" ></el-avatar>
                    </div>
                    <div class="answer_information">
                        <div class="user_info" style="color: rgb(255, 251, 0,0.8);">
                            <span>{{ answer.username }}</span>
                            <span style="color: white;opacity: 0.3;font-size: 40%;margin-left: 3%;">{{ formatRelativeTime(answer.created_at) }}</span>
                        </div>
                        <div class="coment_info" style="font-size: 80%;"><article>{{ answer.content }}测试111111111111111111111111111111111111111</article></div>
                    </div>
                    <div class="answer_option">
                        <div class="op">
                            <span style="font-size: 30%;color: cornflowerblue;">{{ answer.like_count}}</span>
                            <span style="font-size: 30%;">likes</span>
                                <template v-if="answer.is_accepted===1">
                                    <span style="color: gold;font-size: 140%;"><el-icon><GoldMedal /></el-icon></span>
                                </template>
                                <template v-else>
                                    <span style="color: chocolate;font-size: 120%;"><el-icon><Medal /></el-icon></span>
                                </template>
                            
                        </div>
                    </div>
                </div>
            </template>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { onBeforeMount, onMounted,ref, watch } from 'vue';
import router from '../../router';
import { useRoute } from 'vue-router';
import { useQuestionStore } from '../../stores/questionStore';
import {formatStandardDate,formatRelativeTime} from '../../utils/date'

const route = useRoute();
const QuestionStore=useQuestionStore();

const fetchData = async (Qid:number)=>{
    try{

        await QuestionStore.fetchQuestionDetail(Qid);

    }catch(err){
        err='获取问题详情失败'
        console.error('错误',err)
    }
}

watch(
    ()=>route.params.id,
    (newRouteId)=>{
        if(newRouteId)
        fetchData(Number(newRouteId));
    },
    { immediate: true }
)
</script>

<style scoped>
    .questionDetailCardCoutainer{
        display: grid;
        grid-template-columns: 1fr 5fr 1fr;
        grid-template-rows: 1fr auto;
        grid-template-areas: 
        "UserInfo Main Coment"
        "UserInfo Answer Coment"
        ;
        border-radius: 5px;
        min-height: 400px;
    }

    .userInfoCard{
        grid-area: UserInfo;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 5px;
        padding: 7px;
    }

        .avaterRegion{
            min-width: 100px;
            min-height: 100px;
            padding: 5px;
            margin: 8px;
            border-radius: 100%;
            background-color: rgb(0, 0, 0,0.7);
        }

        .userAvater{
            width: 100%;
            height: 100%;
            border-radius: 100%;
        }

        .userInfo{
            width: 100%;
            padding: 5px;
            padding-top: 10px;
            margin: 2px;
            min-height: 250px;
            background-color: rgb(0, 0, 0,0.4);
            border-radius: 5px;
            color: rgb(255, 255, 255);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 10px;
        }

    .mainContentCard{
        grid-area: Main;
        display: flex;
        flex-direction: column;
        gap: 5px;
        color: rgb(255, 255, 255);
    }
        .topic{
            width: 97%;
            padding: 15px;
            margin: 8px;
            background-color: rgb(0, 0, 0,0.5);
            border-radius: 5px;
            min-height: 80px;
            box-sizing: border-box;
            display: flex;
            flex-wrap: wrap;

            
        }
        
        .content{
            width: 97%;
            min-height: 500px;
            box-sizing: border-box;
            padding: 15px;
            margin: 8px;
            margin-top: 0px;
            background-color: rgb(0, 0, 0,0.5);
            border-radius: 5px;
            font-size: 90%;
        }

    .comentCard{
        grid-area: Coment;
    }

    .answerCard{
        box-sizing: border-box;
        grid-area: Answer;
        width: 97%;
        min-height: 200px;
        padding: 5px;
        margin: 8px;
        display: flex;
        flex-direction: column;
        gap: 5px;
        background-color: rgb(0, 0, 0,0.5); 
        color: rgb(255, 255, 255,0.7);
    }

        .Acard{
            display: flex;
            justify-content: center;
            padding: 10px;
            margin: 10px;
            min-height: 50px;
            gap: 5px;
            border-top:1px solid rgb(255, 255, 255,0.2);

        }

        .Acard .avater_answer{
            flex: 1;
            border-radius: 5px;
            aspect-ratio: 1/1;
        }

        .Acard .answer_information{
            flex: 8;
            display: flex;
            flex-direction: column;

            gap: 5px;
        }


        .Acard .answer_option{
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
            border-left: 1px dashed rgb(255, 255, 255,0.3);
            padding-left: 5px;
        }

            .Acard .answer_option .op{
                display: flex;
                align-items: center;
                gap: 3px;
                position: absolute;
                top: 5px;
            }


</style>